﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;

using ImageRecognition2.Forms;
using LowLevelGraphics.Filter;
using ImageRecognition2.CustomControls;

namespace ImageRecognition2.Action
{
    /// <summary>
    /// This action is used for SingleLayerMultipleThreshold
    /// </summary>
    public class ActionSingleLayerMultipleThreshold : AbstractCommand
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="ActionSingleLayerMultipleThreshold"/> class.
        /// </summary>
        public ActionSingleLayerMultipleThreshold()
        {
        }

        /// <summary>
        /// Runs the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public override void Run(object sender, EventArgs e)
        {
            FormSingleLayerMultipleThreshold formFilter = new FormSingleLayerMultipleThreshold((Bitmap)MainFormSingleton.ActivePictureBox.BackgroundImage.Clone());
            ListBoxControlItem listBoxControlItem = (ListBoxControlItem)formFilter.customControlListBox1.Items[0];

            SingleLayerMultiThreshold singleLayerMultipleThreshold = new SingleLayerMultiThreshold();

            Control[] aControl = listBoxControlItem.Controls.ToArray<Control>();
            NumericUpDown nud =(NumericUpDown)aControl[1];

            nud.Value = singleLayerMultipleThreshold.R[0].Min;
            nud = (NumericUpDown)aControl[2];
            nud.Value = singleLayerMultipleThreshold.R[0].Max;

            nud = (NumericUpDown)aControl[4];
            nud.Value = singleLayerMultipleThreshold.G[0].Min;
            nud = (NumericUpDown)aControl[5];
            nud.Value = singleLayerMultipleThreshold.G[0].Max;

            nud = (NumericUpDown)aControl[7];
            nud.Value = singleLayerMultipleThreshold.B[0].Min;
            nud = (NumericUpDown)aControl[8];
            nud.Value = singleLayerMultipleThreshold.B[0].Max;


            formFilter.trackbAmount.Visible = false;
            if (formFilter.ShowDialog() != DialogResult.OK) return;
            new SingleLayerMultiThreshold(formFilter.R, formFilter.G, formFilter.B).Execute(MainFormSingleton.ActivePictureBox.BackgroundImage).Dispose();
        }
    }
}
